package streamforce.crypto.user.subscriber;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import streamforce.Stat;
import streamforce.crypto.KPAbe;
import streamforce.crypto.event.TransformedCTEventAll;
import streamforce.crypto.policies.Policy;
//subscriber to the select price policy
//basically decrypt the resulting ciphertext
public class UserSelectAllSimple extends Policy{

	Stat stat;
	public UserSelectAllSimple(KPAbe ch) {
		super(ch);
		stat = new Stat("userThroughput");
		// TODO Auto-generated constructor stub
	}

	static final Log log = LogFactory.getLog(UserSelectAllSimple.class);
	
	//output (timestamp, stockId, price)
	public void update(TransformedCTEventAll event) {
		long start = System.currentTimeMillis();
		int valPrice = this.cryptoHandler.decrypt_simple(event.getUserId(),
				event.getTransformedCipher()[0], event.getOriginalCipher()[0]);
		int valVolume = this.cryptoHandler.decrypt_simple(event.getUserId(),
				event.getTransformedCipher()[1], event.getOriginalCipher()[1]);
		long end = System.currentTimeMillis();
		log.info("decryption time = " + (end - start));
		log.info(event.getTimestamp() + ", " + event.getRealTime()+", "+event.getStockId() + ", "
				+ valPrice + ", " + valVolume);
		stat.update();
	}
}
